﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace IdeaSparx.CoolControls.Website
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            CoolGridView1.PageIndexChanging += new GridViewPageEventHandler(CoolGridView1_PageIndexChanging);
            CoolGridView1.Sorting += new GridViewSortEventHandler(CoolGridView1_Sorting);
        }

        void CoolGridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            var D = GetDummyData();
            CoolGridView1.DataSource = D;
            CoolGridView1.PageIndex = e.NewPageIndex;
            CoolGridView1.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && !IsCallback)
            {
                CoolGridView1.DataSource = GetDummyData();
                CoolGridView1.DataBind();

                CoolGridView3.DataSource = GetDummyData();
                CoolGridView3.DataBind();
            }
        }

        void CoolGridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            var D = GetDummyData();
            D.DefaultView.Sort = e.SortExpression + (e.SortDirection == SortDirection.Ascending ? " ASC" : " DESC");
            CoolGridView1.DataSource = D;
            CoolGridView1.DataBind();

        }

        private DataTable GetDummyData()
        {
            if (Cache["DummyData"] == null)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("Tax ID", typeof(string));

                for (int i = 0; i < 95; i++)
                {
                    dt.Rows.Add(i, "Name " + i.ToString(), Guid.NewGuid().ToString());
                }

                Cache["DummyData"] = dt;
            }

            return (DataTable)Cache["DummyData"];
            //return null;
        }

        protected void Next(Object sender, EventArgs e)
        {
          MultiView1.ActiveViewIndex = 1;

          CoolGridView2.DataSource = GetDummyData();
          CoolGridView2.DataBind();
        }

        protected void Back(Object sender, EventArgs e)
        {
          MultiView1.ActiveViewIndex = 0;

          CoolGridView1.DataSource = GetDummyData();
          CoolGridView1.DataBind();

        }

        protected void CoolGridView3_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //CoolGridView3.Columns[2].Visible = false;
            
        }

        protected void CoolGridView3_RowCreated(object sender, GridViewRowEventArgs e)
        {
            //CoolGridView3.Columns[1].Visible = false;
            if (e.Row.RowType != DataControlRowType.Pager)
            {
                CoolGridView3.Columns[1].HeaderStyle.CssClass = "hiddencol";
                e.Row.Cells[1].CssClass = "hiddencol";
            }
        }

    }
}
